package com.situ.ymall.admin.controller;

import com.github.pagehelper.PageInfo;
import com.situ.ymall.admin.entity.APIResult;
import com.situ.ymall.admin.entity.Goods;
import com.situ.ymall.admin.entity.Order;
import com.situ.ymall.admin.entity.User;
import com.situ.ymall.admin.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.origin.Origin;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/users")
@CrossOrigin( origins = {"*"})
public class UserController {

    @Autowired
    private UserService userService;
    @GetMapping
    public APIResult get(Integer page, Integer limit, User user){

        PageInfo pageInfo = userService.getAll(page,limit,user);
        return APIResult.ok(pageInfo);
    }

    @DeleteMapping
    public APIResult remove(Integer id){
        System.err.println("22222222222222222222");
        User user = userService.remove(id);

        return APIResult.ok(user);
    }
    /*
      恢复商品
   */
    @RequestMapping("/{id}")
    public APIResult recover(@PathVariable("id") Integer id){
        User user = userService.recover(id);
        return APIResult.create(user);
    }

    @PutMapping("/edit")
    public APIResult edit(@RequestBody User user){
        User selectuser = userService.update(user);
        return  APIResult.create(selectuser);
    }

}
